﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using Microsoft.ApplicationBlocks.Data;
namespace AnyOffice.general.system.workflow.flow_type
{
   
    public partial class type_process_user : ModulePage
    {
      
        private int flowid;
        //private string strTemp = "";
        private int id;
       
      

        private void GetDept(SqlConnection conn, int deptId, ref string deptName)
        {
            string commandText = "SELECT [ParentDept],[DeptName] FROM [dbo].[Department] WHERE [DeptId] = " + deptId.ToString();
            DataTable table = SqlHelper.ExecuteDataset(conn, CommandType.Text , commandText).Tables[0];
            if (table.Rows.Count > 0)
            {
                deptName = table.Rows[0]["DeptName"].ToString() + "/" + deptName;
                if (Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()) != 0)
                {
                    this.GetDept(conn, Convert.ToInt32(table.Rows[0]["ParentDept"].ToString()), ref deptName);
                }
            }
        }       


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.flowid = (Request.QueryString["flow_id"] == null) ? 0 : int.Parse(Request.QueryString["flow_id"].ToString());
                this.ViewState["FlowId"] = this.flowid;
                bool flag = Request.QueryString["graph"] != null;
                this.ViewState["IsGraph"] = flag;
                if (flag)
                {
                    this.litButton.Text = "<input type=\"button\" value=\"关闭\" class=\"BigButton\" name=\"back\" onClick=\"window.close();\">";
                }
                else
                {
                    this.litButton.Text = "<input type=\"button\" value=\"返回\" class=\"BigButton\" name=\"back\" onClick=\"history.back();\">";
                }
                this.id = (Request.QueryString["id"] == null) ? 0 : int.Parse(Request.QueryString["id"].ToString());
                this.ViewState["Id"] = this.id;
                DataTable table = new FlowProcessDao().SelectById(base.Conn, this.id);
                if (table.Rows.Count > 0)
                {
                    this.litPrcsId.Text = table.Rows[0]["PrcsId"].ToString();
                    string str = (table.Rows[0]["PrcsDept"] != DBNull.Value) ? table.Rows[0]["PrcsDept"].ToString() : "";
                    this.ToId.Value = str;
                    string str2 = (table.Rows[0]["ToDeptNames"] != DBNull.Value) ? table.Rows[0]["ToDeptNames"].ToString() : "";
                    if ((str2 != string.Empty) && (str != "ALL_DEPT"))
                    {
                        str2 = str2 + ",";
                    }
                    this.ToName.Value = str2;
                    if (table.Rows[0]["PrcsPriv"] != DBNull.Value)
                    {
                        this.ToPriv.Value = table.Rows[0]["PrcsPriv"].ToString();
                    }
                    if ((table.Rows[0]["ToPrivNames"] != DBNull.Value) && (table.Rows[0]["ToPrivNames"].ToString() != string.Empty))
                    {
                        this.ToPrivName.Value = table.Rows[0]["ToPrivNames"].ToString() + ",";
                    }
                    if (table.Rows[0]["PrcsUser"] != DBNull.Value)
                    {
                        if (table.Rows[0]["PrcsUser"].ToString().EndsWith(","))
                        {
                            this.ToUser.Value = table.Rows[0]["PrcsUser"].ToString();
                        }
                        else
                        {
                            this.ToUser.Value = table.Rows[0]["PrcsUser"].ToString() + ",";
                        }
                    }
                    if ((table.Rows[0]["ToUserNames"] != DBNull.Value) && (table.Rows[0]["ToUserNames"].ToString() != string.Empty))
                    {
                        this.ToUserName.Value = table.Rows[0]["ToUserNames"].ToString() + ",";
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                this.id = Convert.ToInt32(this.ViewState["Id"].ToString());
                FlowProcessDao dao2 = new FlowProcessDao();
                FlowProcessData data = new FlowProcessData();
                data.Id = this.id;
                data.PrcsDept = this.ToId.Value;
                data.PrcsPriv = this.ToPriv.Value;
                data.PrcsUser = this.ToUser.Value;
                dao2.SetPrcsUser(base.Conn, data);
                base.CloseConn();
                if (Convert.ToBoolean(this.ViewState["IsGraph"].ToString()))
                {
                    if (!this.Page.IsStartupScriptRegistered("SefClose"))
                    {
                        this.Page.RegisterStartupScript("SefClose", "<script>parent.opener.location.reload();window.close();</script>\n");
                    }
                }
                else
                {
                    Response.Redirect("type_view_list.aspx?flow_id=" + this.ViewState["FlowId"].ToString());
                }
            }
        }

       
    }
}

